import { CourseTimeDao } from '../dao/courseTimeDao';
import { CourseTime } from '../../types/courseTime';
import { Page, PageReq } from '../../types/page';

export class CourseTimeService {
  // 创建课程时间
  static async create(courseTime: Omit<CourseTime, 'id'>) {
    if(courseTime.start_time.length == 4){
      courseTime.start_time = '0'+courseTime.start_time
    }
    if(courseTime.end_time.length == 4){
      courseTime.end_time = '0'+courseTime.end_time
    }
    return CourseTimeDao.create(courseTime);
  }

  // 更新课程时间
  static async update(courseTime: Partial<CourseTime>) {
    if(courseTime.start_time.length == 4){
      courseTime.start_time = '0'+courseTime.start_time
    }
    if(courseTime.end_time.length == 4){
      courseTime.end_time = '0'+courseTime.end_time
    }
    return CourseTimeDao.update(courseTime);
  }

  // 删除课程时间
  static async delete(id: number) {
    return CourseTimeDao.delete(id);
  }

  // 根据ID查询课程时间
  static async findById(id: number): Promise<CourseTime | null> {
    return CourseTimeDao.findById(id);
  }

  // 查询所有课程时间
  static async list(): Promise<CourseTime[]> {
    return CourseTimeDao.list();
  }

  /**
   * 分页查询课程时间列表
   */
  static async page(params: PageReq<CourseTime>): Promise<Page<CourseTime>> {
    return CourseTimeDao.page(params);
  }
}